import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },
  // 园区管理
  {
    path: '/garden',
    component: Layout,
    redirect: '/example/table',
    name: 'Garden',
    meta: { title: '园区管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'building',
        name: 'Building',
        component: () => import('@/views/garden/building/index.vue'),
        meta: { title: '楼宇管理', icon: 'table' }
      },
      {
        path: 'enterprise',
        name: 'Enterprise',
        component: () => import('@/views/garden/enterprise/index.vue'),
        meta: { title: '企业管理', icon: 'tree' }
      }
    ]
  },
  // 行车管理
  {
    path: '/vehicle',
    component: Layout,
    redirect: '/vehicle/region',
    name: 'Vehicle',
    meta: { title: '行车管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'region',
        name: 'Region',
        component: () => import('@/views/vehicle/region/index.vue'),
        meta: { title: '区域管理' }
      },
      {
        path: 'mouth',
        name: 'Mouth',
        component: () => import('@/views/vehicle/month/index.vue'),
        meta: { title: '月卡管理' }
      },
      {
        path: 'park',
        name: 'Park',
        component: () => import('@/views/vehicle/park/index.vue'),
        meta: { title: '停车缴费管理' }
      },
      {
        path: 'charging',
        name: 'Charging',
        component: () => import('@/views/vehicle/park/index.vue'),
        meta: { title: '计费规则管理' }
      }
    ]
  },
  // 物业管理
  {
    path: '/property',
    component: Layout,
    children: [
      {
        path: 'property',
        meta: { title: '物业费管理', icon: 'link' }
      }
    ]
  },
  // 一体杆管理
  {
    path: '/pole',
    component: Layout,
    redirect: '/pole/poles',
    name: 'Pole',
    meta: { title: '一体杆管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'poles',
        name: 'Poles',
        component: () => import('@/views/pole/poles/index.vue'),
        meta: { title: '一体杆管理' }
      },
      {
        path: 'warn',
        name: 'Warn',
        component: () => import('@/views/pole/warn/index.vue'),
        meta: { title: '告警记录' }
      }
    ]
  },
  // 系统管理
  {
    path: '/system',
    component: Layout,
    redirect: '/system/staff',
    name: 'System',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'staff',
        name: 'Staff',
        component: () => import('@/views/system/staff/index.vue'),
        meta: { title: '员工管理' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role/index.vue'),
        meta: { title: '角色管理' }
      },
      {
        path: '/roleAdd',
        component: () => import('@/views/system/role/add.vue')
      }
    ]
  },
  // 添加月卡
  {
    path: '/cardAdd',
    component: () => import('@/views/vehicle/month/monthCard/add-card.vue')
  },
  // 添加企业
  {
    path: '/enterpriseAdd',
    component: () => import('@/views/garden/enterprise/addEnterprise.vue')
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
